package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"todo-list/service"
	"todo-list/utils/responses"
)

// Ping 单纯调用服务器,检查是否在线
func Ping(ctx *gin.Context) {
	ctx.JSON(http.StatusOK, responses.RespSuccess())
}

func ListTaskStatusHandler() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		l := service.GetCommonSrv()
		ctx.JSON(http.StatusOK, responses.RespSuccessWithData(l.ListTaskStatus()))
	}
}

func getToken(ctx *gin.Context) string {
	var token string
	value, exists := ctx.Get("token")
	if exists {
		token = value.(string)
	}
	return token
}

func getUserId(ctx *gin.Context) uint {
	var userId uint
	value, exists := ctx.Get("userId")
	if exists {
		userId = value.(uint)
	}
	return userId
}
